package com.ruoyi.kubernetes.service.impl;

import com.ruoyi.kubernetes.models.CSRRequestData;
import com.ruoyi.kubernetes.models.CSRResponseData;
import com.ruoyi.kubernetes.service.IKubernetesClientCSRService;
import com.ruoyi.kubernetes.service.IKubernetesClientUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class KubernetesClientUserService implements IKubernetesClientUserService {

    @Autowired
    private IKubernetesClientCSRService iKubernetesClientCSRService;

    @Override
    public CSRResponseData createUser(CSRRequestData requestData) {
        CSRResponseData csrResponseData = iKubernetesClientCSRService.createCSR(requestData);
        if (!csrResponseData.isSuccess()){
            return null;
        }
        String crt = iKubernetesClientCSRService.approveCSR(requestData.getUsername());
        if(crt==null){
            return null;
        }
        csrResponseData.setClient_crt(crt);
        return csrResponseData;
    }
}
